<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>将十进制转为二进制</title>
	</head>
	<body>
		<script src="./Stack.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript">
			function dec2bin(decNumber) {
				// 创建栈
				const stack = new Stack()
				
				while (decNumber > 0) {
					// 把余数压入栈
					stack.push(decNumber % 2)
					
					decNumber = Math.floor(decNumber / 2)
				}
				
				// 出栈
				var binaryString = '';
				while(!stack.isEmty()) {
					binaryString += stack.pop()
				}
				return binaryString
			}
			alert(dec2bin(1000))
		</script>
	</body>
</html>
